package com.gpj.learn.rabbitmq.springboot.service;

import com.gpj.learn.rabbitmq.springboot.common.MessageType;
import com.gpj.learn.rabbitmq.springboot.common.MyMessage;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class ConcumerReceiver {
	private static final String TEST_WORK_QUEUE = "queue-work";
	private static final String TEST_FANOUT = "queue-fanout";
	private static final String TEST_ROUTING = "queue-routing";
	private static final String TEST_TOPIC = "queue-topic";

	//工作队列模式
	@RabbitListener(queues = TEST_WORK_QUEUE)
	public void wordQueueReceive(String message) {
		System.out.println("Concumer1 工作队列模式 received message : " + message);
	}

	//pub/sub模式进行消息监听
	@RabbitListener(queues = TEST_FANOUT)
	public void fanoutReceive(String message) {
		System.out.println("Concumer1 发布订阅模式 received message : " + message);
	}

	//Routing路由模式
	@RabbitListener(queues = TEST_ROUTING)
	public void routingReceive(String message) {
		System.out.println("Concumer1 Routing路由模式 received message : " + message);
	}

	//topic 模式
	//注意这个模式会有优先匹配原则。例如发送routingKey=hunan.IT,那匹配到hunan.*(hunan.IT,hunan.eco),之后就不会再去匹配*.ITd
	@RabbitListener(queues = TEST_TOPIC)
	public void topicReceive(MyMessage message) {
		System.out.println("Concumer1 Topic路由模式 received message : " + message);
	}
}
